<template>
  <div v-show="$route.name === 'store-back-detail'">
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/store-back-list' }">退货单列表</el-breadcrumb-item>
      <el-breadcrumb-item>退货单详情</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域--订单数据修改 -->
    <el-card>
      <el-form :model="saveForm"
        ref="saveFormRef"
        label-width="110px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="退货单号" prop="apply_number" style="width: 300px;">
              <el-input v-model="saveForm.apply_number" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="退货时间" prop="back_time" style="width: 300px;">
              <el-date-picker type="date" placeholder="选择日期" v-model="saveForm.back_time" readonly>
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table
      border
      v-loading="loading"
      :data="saveForm.detail"
      style="margin-top: 10px;">
        <el-table-column type="index" width="60" align="center"></el-table-column>
        <el-table-column label="门店" prop="basename" min-width="130" align="center"></el-table-column>
        <el-table-column label="分类" prop="category_name" min-width="130" align="center"></el-table-column>
        <el-table-column label="商品" prop="name" min-width="130" align="center"></el-table-column>
        <el-table-column label="数量" min-width="80" align="center">
          <template slot-scope="scope">
            <span>{{ parseFloat(scope.row.count).toFixed(2) }}</span>
          </template>
        </el-table-column>
      </el-table>
      <el-row>
        <el-col :span="24">
          <el-button  @click="back" style="margin-left: 5px;margin-top: 10px;">返回</el-button>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      back_id: '',
      saveForm: {
        back_time: '',
        apply_number: '',
        detail: [],
      },
      loading: false
    }
  },
  mounted() {
    this.getBackData()
  },
  methods: {
    getBackData() {
      if (this.$route.params.back_id) {
        this.back_id = this.$route.params.back_id
        localStorage.setItem('backId', this.$route.params.back_id)
      } else {
        this.back_id = localStorage.getItem('backId')
      }
      if (this.back_id) {
        this.getBackDetail(this.back_id)
      }
    },
    async getBackDetail(back_id) {
      const { data: result } = await this.$http.get('/store-back/' + back_id)
      if (result.status !== 200) {
        this.loading = false
        return this.$message.error(result.msg)
      }
      this.loading = false
      this.saveForm = result.data
    },
    back () {
      localStorage.removeItem('backId')
      this.$router.push({ 'name': 'store-back-list' })
    }
  }
}
</script>